<template>
  <div id="postTopSearch">
    <h1 class="con-right-title">
      菜单管理
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="菜单名称" prop="menuName">
          <el-input
            v-model="formInline.menuName"
            placeholder="请输入关键词搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="菜单状态" prop="visible">
          <el-select v-model="formInline.visible" placeholder="请选择菜单状态">
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'PostTopSearch',
  msg: '菜单管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          menuName: '', // 菜单名称
          visible: '' // 菜单状态,默认所有
        }
      }
    }
  },
  data() {
    return {
      statusList: [
        // 菜单状态
        { dictLabel: '所有', dictValue: '' }
      ],
      rules: {
        menuName: {},
        visible: {}
      }
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    },
    /* 获取菜单状态 */
    async getStatusList() {
      this.statusList = this.statusList.concat(await sysNormalDisable('sys_show_hide','hideShow'))
    }
  }
}
</script>

<style lang="less"></style>
